package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.DimensionsMapper;
import com.tanhua.model.db.Dimensions;
import com.tanhua.model.vo.DimensionsVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@DubboService
public class DimensionsApiImpl implements DimensionsApi {

    @Autowired
    private DimensionsMapper dimensionsMapper;

    //通过reportid查询dimensions
    @Override
    public List<DimensionsVo> findByReportId(Long id) {
        QueryWrapper<Dimensions> wrapper = new QueryWrapper<>();
        wrapper.eq("report_id",id);
        List<Dimensions> dimensions = dimensionsMapper.selectList(wrapper);
        List<DimensionsVo> vos = new ArrayList<>();
        for (Dimensions dimension : dimensions) {
            DimensionsVo vo = DimensionsVo.inint(dimension);
            vos.add(vo);
        }
        return vos;
    }

    //保存维度
    @Override
    public void save(List<Dimensions> dimensions) {
        for (Dimensions dimension : dimensions) {
            dimensionsMapper.insert(dimension);
        }
    }
}
